using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
    /// <summary>
    /// Summary description for ctlNameEntry.
    /// </summary>
    public class ctlNameEntry : Control
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private System.Windows.Forms.TabControl tabControl;
        private System.Windows.Forms.TabPage tabTitle;
        private System.Windows.Forms.ComboBox cbTitle;
        private System.Windows.Forms.Label lblTitle;
        private System.Windows.Forms.TabPage tabName;
        private System.Windows.Forms.TextBox txtFName;
        private System.Windows.Forms.Label lblFName;
        private System.Windows.Forms.TabPage tabMName;
        private System.Windows.Forms.TextBox txtMiddleName;
        private System.Windows.Forms.Label lblMiddle;
        private System.Windows.Forms.TabPage tabLName;
        private System.Windows.Forms.TextBox txtLName;
        private System.Windows.Forms.Label lblLName;
        private System.Windows.Forms.TabPage tabSuffix;
        private System.Windows.Forms.ComboBox cbSuffix;
        private System.Windows.Forms.Label lblSuffix;
        private NameEntry m_objEntry;
        private int m_nSelected = 0;
        private Microsoft.WindowsCE.Forms.InputPanel pnlSIP;

        public ctlNameEntry()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            m_objEntry = null;
            pnlSIP = null;
        }

        public NameEntry Entry
        {
            get { return m_objEntry; }
            set { m_objEntry = value; }
        }

        public Microsoft.WindowsCE.Forms.InputPanel SIPPanel
        {
            get { return pnlSIP; }
            set { pnlSIP = value; }
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                    components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.tabControl = new System.Windows.Forms.TabControl();
            this.tabTitle = new System.Windows.Forms.TabPage();
            this.cbTitle = new System.Windows.Forms.ComboBox();
            this.lblTitle = new System.Windows.Forms.Label();
            this.tabName = new System.Windows.Forms.TabPage();
            this.txtFName = new System.Windows.Forms.TextBox();
            this.lblFName = new System.Windows.Forms.Label();
            this.tabMName = new System.Windows.Forms.TabPage();
            this.txtMiddleName = new System.Windows.Forms.TextBox();
            this.lblMiddle = new System.Windows.Forms.Label();
            this.tabLName = new System.Windows.Forms.TabPage();
            this.txtLName = new System.Windows.Forms.TextBox();
            this.lblLName = new System.Windows.Forms.Label();
            this.tabSuffix = new System.Windows.Forms.TabPage();
            this.cbSuffix = new System.Windows.Forms.ComboBox();
            this.lblSuffix = new System.Windows.Forms.Label();
            // 
            // tabControl
            // 
            this.tabControl.Controls.Add(this.tabTitle);
            this.tabControl.Controls.Add(this.tabName);
            this.tabControl.Controls.Add(this.tabMName);
            this.tabControl.Controls.Add(this.tabLName);
            this.tabControl.Controls.Add(this.tabSuffix);
            this.tabControl.Location = new System.Drawing.Point(3, 6);
            this.tabControl.SelectedIndex = 0;
            this.tabControl.Size = new System.Drawing.Size(230, 140);
            this.tabControl.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
            // 
            // tabTitle
            // 
            this.tabTitle.Controls.Add(this.cbTitle);
            this.tabTitle.Controls.Add(this.lblTitle);
            this.tabTitle.Location = new System.Drawing.Point(4, 22);
            this.tabTitle.Size = new System.Drawing.Size(222, 114);
            this.tabTitle.Text = "Title";
            // 
            // cbTitle
            // 
            this.cbTitle.Items.Add("Dr.");
            this.cbTitle.Items.Add("Mr.");
            this.cbTitle.Items.Add("Ms.");
            this.cbTitle.Items.Add("Mrs.");
            this.cbTitle.Location = new System.Drawing.Point(103, 47);
            this.cbTitle.Size = new System.Drawing.Size(60, 21);
            // 
            // lblTitle
            // 
            this.lblTitle.Location = new System.Drawing.Point(59, 47);
            this.lblTitle.Size = new System.Drawing.Size(32, 20);
            this.lblTitle.Text = "Title:";
            this.lblTitle.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // tabName
            // 
            this.tabName.Controls.Add(this.txtFName);
            this.tabName.Controls.Add(this.lblFName);
            this.tabName.Location = new System.Drawing.Point(4, 22);
            this.tabName.Size = new System.Drawing.Size(222, 114);
            this.tabName.Text = "FName";
            this.tabName.Visible = false;
            // 
            // txtFName
            // 
            this.txtFName.Location = new System.Drawing.Point(6, 63);
            this.txtFName.Size = new System.Drawing.Size(212, 20);
            this.txtFName.Text = "";
            this.txtFName.GotFocus += new EventHandler(txtFName_GotFocus);
            // 
            // lblFName
            // 
            this.lblFName.Location = new System.Drawing.Point(4, 31);
            this.lblFName.Size = new System.Drawing.Size(68, 20);
            this.lblFName.Text = "First Name:";
            this.lblFName.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // tabMName
            // 
            this.tabMName.Controls.Add(this.txtMiddleName);
            this.tabMName.Controls.Add(this.lblMiddle);
            this.tabMName.Location = new System.Drawing.Point(4, 22);
            this.tabMName.Size = new System.Drawing.Size(222, 114);
            this.tabMName.Text = "MName";
            this.tabMName.Visible = false;
            // 
            // txtMiddleName
            // 
            this.txtMiddleName.Location = new System.Drawing.Point(5, 63);
            this.txtMiddleName.Size = new System.Drawing.Size(212, 20);
            this.txtMiddleName.Text = "";
            this.txtMiddleName.GotFocus += new EventHandler(txtMiddleName_GotFocus);
            // 
            // lblMiddle
            // 
            this.lblMiddle.Location = new System.Drawing.Point(5, 31);
            this.lblMiddle.Size = new System.Drawing.Size(68, 20);
            this.lblMiddle.Text = "M. I.:";
            // 
            // tabLName
            // 
            this.tabLName.Controls.Add(this.txtLName);
            this.tabLName.Controls.Add(this.lblLName);
            this.tabLName.Location = new System.Drawing.Point(4, 22);
            this.tabLName.Size = new System.Drawing.Size(222, 114);
            this.tabLName.Text = "LName";
            this.tabLName.Visible = false;
            // 
            // txtLName
            // 
            this.txtLName.Location = new System.Drawing.Point(5, 63);
            this.txtLName.Size = new System.Drawing.Size(212, 20);
            this.txtLName.Text = "";
            this.txtLName.GotFocus += new EventHandler(txtLName_GotFocus);
            // 
            // lblLName
            // 
            this.lblLName.Location = new System.Drawing.Point(5, 31);
            this.lblLName.Size = new System.Drawing.Size(68, 20);
            this.lblLName.Text = "Last Name:";
            this.lblLName.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // tabSuffix
            // 
            this.tabSuffix.Controls.Add(this.cbSuffix);
            this.tabSuffix.Controls.Add(this.lblSuffix);
            this.tabSuffix.Location = new System.Drawing.Point(4, 22);
            this.tabSuffix.Size = new System.Drawing.Size(222, 114);
            this.tabSuffix.Text = "Suffix";
            this.tabSuffix.Visible = false;
            // 
            // cbSuffix
            // 
            this.cbSuffix.Items.Add("Sr.");
            this.cbSuffix.Items.Add("Jr.");
            this.cbSuffix.Items.Add("II");
            this.cbSuffix.Items.Add("III");
            this.cbSuffix.Location = new System.Drawing.Point(103, 47);
            this.cbSuffix.Size = new System.Drawing.Size(64, 21);
            // 
            // lblSuffix
            // 
            this.lblSuffix.Location = new System.Drawing.Point(55, 47);
            this.lblSuffix.Size = new System.Drawing.Size(40, 20);
            this.lblSuffix.Text = "Suffix:";
            this.lblSuffix.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // ctlNameEntry
            // 
            this.Controls.Add(this.tabControl);
            this.Size = new System.Drawing.Size(236, 152);

        }
        #endregion

        public void LoadSettings()
        {
            tabControl.SelectedIndex = 0;

            if (m_objEntry != null)
            {
                tabControl.SelectedIndex = 0;

                if (!String.IsNullOrEmpty(m_objEntry.Title))
                {
                    cbTitle.Text = m_objEntry.Title;
                }
                else
                {
                    cbTitle.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Given))
                {
                    txtFName.Text = m_objEntry.Given;
                }
                else
                {
                    txtFName.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Middle))
                {
                    txtMiddleName.Text = m_objEntry.Middle;
                }
                else
                {
                    txtMiddleName.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Family))
                {
                    txtLName.Text = m_objEntry.Family;
                }
                else
                {
                    txtLName.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Suffix))
                {
                    cbSuffix.Text = m_objEntry.Suffix;
                }
                else
                {
                    cbSuffix.Text = "";
                }
            }
        }

        public void SaveSettings()
        {
            if (m_objEntry != null)
            {
                m_objEntry.NameTitle = cbTitle.Text;
                m_objEntry.Given = txtFName.Text;
                m_objEntry.Middle = txtMiddleName.Text;
                m_objEntry.Family = txtLName.Text;
                m_objEntry.Suffix = cbSuffix.Text;
            }
        }

        private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nIndex = tabControl.SelectedIndex;
            tabControl.TabPages[m_nSelected].Visible = false;
            tabControl.TabPages[nIndex].Visible = true;
            m_nSelected = nIndex;
        }

        private void txtFName_GotFocus(object sender, EventArgs e)
        {
            pnlSIP.Enabled = true;
        }

        private void txtMiddleName_GotFocus(object sender, EventArgs e)
        {
            pnlSIP.Enabled = true;
        }

        private void txtLName_GotFocus(object sender, EventArgs e)
        {
            pnlSIP.Enabled = true;
        }
    }
}
